package src.rmi;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Set;

import src.common.MessageStatus;
import src.dto.LightMailBoxDTO;
import src.dto.MailBoxDTO;
import src.dto.OutgoingMessageDTO;
import src.service.MailServerService;
import src.service.MailServerServiceDTO;

public class ImplementationServiceDTO extends UnicastRemoteObject implements
		ServiceDTO {

	public ImplementationServiceDTO() throws RemoteException {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * 
	 */
	private ServiceDTO service;
	private static final long serialVersionUID = 1L;

	public void initService() {
		try {
			this.service = new ImplementationServiceDTO();
			Naming.rebind("//localhost/ServidorServicioDTO", service);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	@Override
	public MailBoxDTO signIn(String nameMailBox, String passMailBox) {
		return MailServerServiceDTO.getInstance().signIn(nameMailBox,
				passMailBox);
	}

	@Override
	public void sendMessage(OutgoingMessageDTO outgoingMessageDTO) {
		MailServerServiceDTO.getInstance().sendMessage(outgoingMessageDTO);
	}

	@Override
	public void changeMessageStatus(long idIncomingMessage,
			MessageStatus messageStatus) {
		MailServerService.getInstance().changeMessageStatus(idIncomingMessage,
				messageStatus);
	}

	@Override
	public void deleteIncomingMessage(long idIncomingMessage)
			throws RemoteException {
		MailServerServiceDTO.getInstance().deleteIncomingMessage(idIncomingMessage);
	}
	
	@Override
	public Set<OutgoingMessageDTO> getOutgoingMessagesByMailBox(long idMailBox){
		return MailServerServiceDTO.getInstance().getOutgoingMessagesByMailBox(idMailBox);
	}

	@Override
	public Set<LightMailBoxDTO> getContactsByMailBox(long idMailBox){
		return MailServerServiceDTO.getInstance().getContactsByMailBox(idMailBox);
	}
	
	@Override
	public boolean changePassword(long idMailBox,String oldPass,String newPass)throws RemoteException{
		return MailServerServiceDTO.getInstance().changePassword(idMailBox, oldPass, newPass);
	}
}
